<template>
	<!-- 器官设置 -->
	<div class="page-wrap">
		<div class="page-content p-0">
			<div class="page-column p-0">
				<div class="page-form p-x-0">
					<el-form
						:model="ruleForm"
						:rules="rules"
						label-position="left"
						label-width="140px"
						ref="form"
						label-suffix="："
					>
						<el-row>
							<el-col :span="24">
								<el-form-item label="事故日期总天数" prop="NUMDATES001">
									<select-para
										size="medium"
										class="mediumForm"
										v-model="ruleForm.NUMDATES001"
										:label.sync="ruleForm.NUMDATES001"
										:options="NUMDATES001options"
									></select-para>
								</el-form-item>
								<el-form-item label="事故第几天"></el-form-item>
								<el-table ref="multipleTable" :data="ruleForm.ACCDATES001tab" tooltip-effect="dark" border>
									<el-table-column
										prop="RDCORINV_COR1"
										label="1"
										align="center"
										min-width="120"
										v-if="
												this.ruleForm.NUMDATES001 >= 1
											"
									>
										<template slot-scope="scope">
											<el-form-item
												label-width="0px"
												:rules="rules.RDCORINV_COR1"
												:prop="'ACCDATES001tab.'+scope.$index+'.RDCORINV_COR1'"
											>
												<el-input
													minlength="1"
													maxlength="20"
													oninput="value=value.replace(/^\D*(\d*(?:\.\d{0,20})?).*$/g, '$1')"
													class="bigForm"
													v-model="scope.row.RDCORINV_COR1"
												></el-input>
											</el-form-item>
										</template>
									</el-table-column>
									<el-table-column
										prop="RDCORINV_COR2"
										label="2"
										align="center"
										min-width="120"
										v-if="
												this.ruleForm.NUMDATES001 >= 2
											"
									>
										<template slot-scope="scope">
											<el-form-item
												label-width="0px"
												:rules="rules.RDCORINV_COR2"
												:prop="'ACCDATES001tab.'+scope.$index+'.RDCORINV_COR2'"
											>
												<el-input
													minlength="1"
													maxlength="20"
													oninput="value=value.replace(/^\D*(\d*(?:\.\d{0,20})?).*$/g, '$1')"
													class="bigForm"
													v-model="scope.row.RDCORINV_COR2"
												></el-input>
											</el-form-item>
										</template>
									</el-table-column>
									<el-table-column
										prop="RDCORINV_COR3"
										label="3"
										align="center"
										min-width="120"
										v-if="
												this.ruleForm.NUMDATES001 >= 3
											"
									>
										<template slot-scope="scope">
											<el-form-item
												label-width="0px"
												:rules="rules.RDCORINV_COR3"
												:prop="'ACCDATES001tab.'+scope.$index+'.RDCORINV_COR3'"
											>
												<el-input
													minlength="1"
													maxlength="20"
													oninput="value=value.replace(/^\D*(\d*(?:\.\d{0,20})?).*$/g, '$1')"
													class="bigForm"
													v-model="scope.row.RDCORINV_COR3"
												></el-input>
											</el-form-item>
										</template>
									</el-table-column>
									<el-table-column
										prop="RDCORINV_COR4"
										label="4"
										align="center"
										min-width="120"
										v-if="
												this.ruleForm.NUMDATES001 >= 4
											"
									>
										<template slot-scope="scope">
											<el-form-item
												label-width="0px"
												:rules="rules.RDCORINV_COR4"
												:prop="'ACCDATES001tab.'+scope.$index+'.RDCORINV_COR4'"
											>
												<el-input
													minlength="1"
													maxlength="20"
													oninput="value=value.replace(/^\D*(\d*(?:\.\d{0,20})?).*$/g, '$1')"
													class="bigForm"
													v-model="scope.row.RDCORINV_COR4"
												></el-input>
											</el-form-item>
										</template>
									</el-table-column>
									<el-table-column
										prop="RDCORINV_COR5"
										label="5"
										align="center"
										min-width="120"
										v-if="
												this.ruleForm.NUMDATES001 >= 5
											"
									>
										<template slot-scope="scope">
											<el-form-item
												label-width="0px"
												:rules="rules.RDCORINV_COR5"
												:prop="'ACCDATES001tab.'+scope.$index+'.RDCORINV_COR5'"
											>
												<el-input
													minlength="1"
													maxlength="20"
													oninput="value=value.replace(/^\D*(\d*(?:\.\d{0,20})?).*$/g, '$1')"
													class="bigForm"
													v-model="scope.row.RDCORINV_COR5"
												></el-input>
											</el-form-item>
										</template>
									</el-table-column>
									<el-table-column
										prop="RDCORINV_COR6"
										label="6"
										align="center"
										min-width="120"
										v-if="
												this.ruleForm.NUMDATES001 >= 6
											"
									>
										<template slot-scope="scope">
											<el-form-item
												label-width="0px"
												:rules="rules.RDCORINV_COR6"
												:prop="'ACCDATES001tab.'+scope.$index+'.RDCORINV_COR6'"
											>
												<el-input
													minlength="1"
													maxlength="20"
													oninput="value=value.replace(/^\D*(\d*(?:\.\d{0,20})?).*$/g, '$1')"
													class="bigForm"
													v-model="scope.row.RDCORINV_COR6"
												></el-input>
											</el-form-item>
										</template>
									</el-table-column>
									<el-table-column
										prop="RDCORINV_COR7"
										label="7"
										align="center"
										min-width="120"
										v-if="
												this.ruleForm.NUMDATES001 >= 7
											"
									>
										<template slot-scope="scope">
											<el-form-item
												label-width="0px"
												:rules="rules.RDCORINV_COR7"
												:prop="'ACCDATES001tab.'+scope.$index+'.RDCORINV_COR7'"
											>
												<el-input
													minlength="1"
													maxlength="20"
													oninput="value=value.replace(/^\D*(\d*(?:\.\d{0,20})?).*$/g, '$1')"
													class="bigForm"
													v-model="scope.row.RDCORINV_COR7"
												></el-input>
											</el-form-item>
										</template>
									</el-table-column>
									<el-table-column
										prop="RDCORINV_COR8"
										label="8"
										align="center"
										min-width="120"
										v-if="
												this.ruleForm.NUMDATES001 >= 8
											"
									>
										<template slot-scope="scope">
											<el-form-item
												label-width="0px"
												:rules="rules.RDCORINV_COR8"
												:prop="'ACCDATES001tab.'+scope.$index+'.RDCORINV_COR8'"
											>
												<el-input
													minlength="1"
													maxlength="20"
													oninput="value=value.replace(/^\D*(\d*(?:\.\d{0,20})?).*$/g, '$1')"
													class="bigForm"
													v-model="scope.row.RDCORINV_COR8"
												></el-input>
											</el-form-item>
										</template>
									</el-table-column>
									<el-table-column
										prop="RDCORINV_COR9"
										label="9"
										align="center"
										min-width="120"
										v-if="
												this.ruleForm.NUMDATES001 >= 9
											"
									>
										<template slot-scope="scope">
											<el-form-item
												label-width="0px"
												:rules="rules.RDCORINV_COR9"
												:prop="'ACCDATES001tab.'+scope.$index+'.RDCORINV_COR9'"
											>
												<el-input
													minlength="1"
													maxlength="20"
													oninput="value=value.replace(/^\D*(\d*(?:\.\d{0,20})?).*$/g, '$1')"
													class="bigForm"
													v-model="scope.row.RDCORINV_COR9"
												></el-input>
											</el-form-item>
										</template>
									</el-table-column>
									<el-table-column
										prop="RDCORINV_COR10"
										label="10"
										align="center"
										min-width="120"
										v-if="
												this.ruleForm.NUMDATES001 >= 10
											"
									>
										<template slot-scope="scope">
											<el-form-item
												label-width="0px"
												:rules="rules.RDCORINV_COR10"
												:prop="'ACCDATES001tab.'+scope.$index+'.RDCORINV_COR10'"
											>
												<el-input
													minlength="1"
													maxlength="20"
													oninput="value=value.replace(/^\D*(\d*(?:\.\d{0,20})?).*$/g, '$1')"
													class="bigForm"
													v-model="scope.row.RDCORINV_COR10"
												></el-input>
											</el-form-item>
										</template>
									</el-table-column>
								</el-table>
							</el-col>
						</el-row>
					</el-form>
				</div>
				<div class="bottom-btn">
					<el-button type="primary" :loading="loading" @click="submitFun">下一步</el-button>
				</div>
			</div>
		</div>
	</div>
</template>

<script>
import selectPara from "@/components/selectPara"
import commCheckbox from "@/components/commCheckbox"
import ImageCropper from "@/components/ImageCropper"
import FixBottomButton from "@/components/FixBottomButton"
import ueditor from "@/components/ueditor"
import textLength from "@/components/common/comp/textLength"
import { commPara } from "@/mixins/mixins"
import { mapState } from "vuex"
import { dome } from "@/utils/verify.js"
// import {
//     saveslbaseinfo,
//     slbaseinfo
// } from '../service.js';
export default {
	name: "aboutUs",
	props: {},
	mixins: [commPara],
	components: {
		selectPara,
		ImageCropper,
		textLength,
		commCheckbox,
		FixBottomButton,
		ueditor,
	},
	computed: {
		...mapState({
			ingestion_Data: (state) => state.token.ingestion_Data,
		}),
	},
	data() {
		return {
			activeTab: "3",
			ruleForm: {
				NUMDATES001: "",
				ACCDATES001tab: [],
			},
			rules: {
				NUMDATES001: [
					{
						required: true,
						message: "请选择",
						trigger: "change",
					},
				],
				RDCORINV_COR1: [
					{
						validator: dome(1, 365),
						trigger: ["change", "blur"],
					},
				],
				RDCORINV_COR2: [
					{
						validator: dome(1, 365),
						trigger: ["change", "blur"],
					},
				],
				RDCORINV_COR3: [
					{
						validator: dome(1, 365),
						trigger: ["change", "blur"],
					},
				],
				RDCORINV_COR4: [
					{
						validator: dome(1, 365),
						trigger: ["change", "blur"],
					},
				],
				RDCORINV_COR5: [
					{
						validator: dome(1, 365),
						trigger: ["change", "blur"],
					},
				],
				RDCORINV_COR6: [
					{
						validator: dome(1, 365),
						trigger: ["change", "blur"],
					},
				],
				RDCORINV_COR7: [
					{
						validator: dome(1, 365),
						trigger: ["change", "blur"],
					},
				],
				RDCORINV_COR8: [
					{
						validator: dome(1, 365),
						trigger: ["change", "blur"],
					},
				],
				RDCORINV_COR9: [
					{
						validator: dome(1, 365),
						trigger: ["change", "blur"],
					},
				],
			},
			NUMDATES001options: [],

			loading: false,
		}
	},
	mounted() {
		this.setDDNPSGRPoptions()
		this.setData()
	},
	methods: {
		setDDNPSGRPoptions() {
			this.NUMDATES001options = []
			for (let index = 0; index < 9; index++) {
				this.NUMDATES001options.push({
					label: index + 1,
					value: index + 1,
				})
			}

			this.ruleForm.ACCDATES001tab = [
				{
					RDCORINV_COR1: "1",
					RDCORINV_COR2: "61",
					RDCORINV_COR3: "121",
					RDCORINV_COR4: "151",
					RDCORINV_COR5: "181",
					RDCORINV_COR6: "201",
					RDCORINV_COR7: "241",
					RDCORINV_COR8: "271",
					RDCORINV_COR9: "301",
				},
			]
		},
		setData() {
			this.ruleForm.NUMDATES001 = this.ingestion_Data.NUMDATES001
				? this.ingestion_Data.NUMDATES001.toString()
				: "0"
			if (this.ingestion_Data.NUMDATES001 > 0) {
				this.ingestion_Data.ACCDATES001.forEach((item, index) => {
					let n = index + 1
					this.ruleForm.ACCDATES001tab[0]["RDCORINV_COR" + n] = item
				})
			}
		},
		submitFun() {
			//保存
			this.$refs.form.validate((valid) => {
				if (valid) {
					let tempACCDATES001 = [] 
					for (const key in this.ruleForm.ACCDATES001tab[0]) {
						if (
							this.ruleForm.ACCDATES001tab[0].hasOwnProperty(key)
						) {
							const element = this.ruleForm.ACCDATES001tab[0][key]
							tempACCDATES001.push(parseInt(element))
						}
					}
					tempACCDATES001.splice(this.ruleForm.NUMDATES001) 
					let tempdata = JSON.parse(
						JSON.stringify(this.ingestion_Data)
					)

					tempdata.NUMDATES001 = this.ruleForm.NUMDATES001
					tempdata.ACCDATES001 = tempACCDATES001
					tempdata.SETPAGEINDEX = this.activeTab
					this.$store.dispatch("upData_ingestion_Data", tempdata) 
					let params = {
						batchid: this.$route.query.id,
						batchinfo: "SHIRU",
						submitjson: JSON.stringify(tempdata),
					}
					this.$appApi
						.BATCH_SUBMIT(params)
						.then((res) => {
							var str = res.data.substring(0, 1)
							if (str == "E") {
								let message = res.data.substring(6)
								this.$notify.error({
									title: "提交失败！",
									message: message,
									type: "success",
								})
							} else if (str == "S") {
								this.$notify({
									message: "提交成功！",
									type: "success",
								})
							}
						})
						.catch((err) => {
							console.log(err)
						})
					this.$emit("changeActiveTab", this.activeTab)
					this.$store.dispatch(
						"change_ingestion_showTab",
						this.activeTab
					)
				}
			})
		},
	},
}
</script>
<style lang="scss" scoped>
.page-flex-row /deep/ .el-collapse-item__header {
	background: #f3f9fe;
}
</style>